package com.example.admintor.threehome.fragment;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.admintor.threehome.activity.MainActivity;
import com.example.admintor.threehome.data.Datas;
import com.example.admintor.threehome.R;
import com.example.admintor.threehome.activity.LoginActivity;
import com.example.admintor.threehome.data.ReciveDateHander;
import com.example.wzsdk.login.Landing;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Admintor on 2017/12/5.
 */

public class FourFragment extends Fragment {

    @BindView(R.id.jd_img)
    ImageView jd_img;

    @BindView(R.id.rt_icon)
    ImageView rt_icon;

    @BindView(R.id.fs_btn)
    ImageView fs_btn;

    @BindView(R.id.sf_img)
    ImageView sf_img;

    @BindView(R.id.fs_img)
    ImageView fs_img;

    @BindView(R.id.mj_icon)
    ImageView mj_icon;

    @BindView(R.id.dd_img)
    ImageView dd_img;

    @BindView(R.id.jk_icon)
    ImageView jk_icon;

    @BindView(R.id.up)
    Button up;

    @BindView(R.id.down)
    Button down;

    @BindView(R.id.sfeng)
    Button sfeng;

    @BindView(R.id.kt_str)
    TextView kt_str;
    private boolean jd_state, fs_state, dd_state, sf_state, cl_state;
    private int num = 22;
    private ReciveDateHander reciveDateHander;
    private Landing wzoneLanding;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_four, container, false);
        ButterKnife.bind(this, view);
        return view;
    }


    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        reciveDateHander = ((MainActivity) activity).getReciveDateHander();
        wzoneLanding = reciveDateHander.getWzoneLanding();
    }





    @OnClick(R.id.up)
    public void OnClickUp() {
       wzoneLanding.setKeyByUiid(Datas.KT_Uiid, Datas.KT_UP);
        kt_str.setText(num++ + " ℃");
    }

    @OnClick(R.id.down)
    public void OnClickDown() {
       wzoneLanding.setKeyByUiid(Datas.KT_Uiid, Datas.KT_DOWN);
        kt_str.setText(num-- + " ℃");
    }

    @OnClick(R.id.sfeng)
    public void OnClickSf() {
        if (sf_state == false) {
            sf_img.setBackgroundResource(R.drawable.sf_on);
            sf_state = true;
        } else {
            sf_img.setBackgroundResource(R.drawable.sf_off);
            sf_state = false;
        }
       wzoneLanding.setKeyByUiid(Datas.KT_Uiid, Datas.KT_SAO);
    }

    @OnClick(R.id.jd_img)
    public void OnClickJd() {
        if (jd_state == false) {
            jd_img.setBackgroundResource(R.drawable.on);
            jd_state = true;
        } else {
            jd_img.setBackgroundResource(R.drawable.off);
            jd_state = false;
        }
       wzoneLanding.setKeyByUiid(Datas.KT_Uiid, Datas.KT_ClOSE_OR_OPEN);
    }

    @OnClick(R.id.fs_btn)
    public void OnClickFS() {
        if (cl_state == false) {
            fs_btn.setBackgroundResource(R.drawable.on);
            rt_icon.setBackgroundResource(R.drawable.cl_open);
           wzoneLanding.setKeyByUiid(Datas.CL_Uiid, Datas.CL_OPEN);
            cl_state = true;
        } else {
            fs_btn.setBackgroundResource(R.drawable.off);
            rt_icon.setBackgroundResource(R.drawable.cl_close);
           wzoneLanding.setKeyByUiid(Datas.CL_Uiid, Datas.CL_ClOSE);
            cl_state = false;
        }

    }

    @OnClick(R.id.fs_img)
    public void OnClickFs() {
        if (fs_state == false) {
           wzoneLanding.setKeyByUiid(Datas.FS_Uiid, Datas.FS_OPEN);
            mj_icon.setBackgroundResource(R.drawable.fs_open);
            fs_img.setBackgroundResource(R.drawable.on);
            fs_state = true;
        } else {
           wzoneLanding.setKeyByUiid(Datas.FS_Uiid, Datas.FS_ClOSE);
            mj_icon.setBackgroundResource(R.drawable.fs_close);
            fs_img.setBackgroundResource(R.drawable.off);
            fs_state = false;
        }
    }

    @OnClick(R.id.dd_img)
    public void OnClickDd() {
        if (dd_state == false) {
           wzoneLanding.setKeyByUiid(Datas.DD_Uiid, Datas.DD_OPEN);
            jk_icon.setBackgroundResource(R.drawable.dd_open);
            dd_img.setBackgroundResource(R.drawable.on);
            dd_state = true;
        } else {
           wzoneLanding.setKeyByUiid(Datas.DD_Uiid, Datas.DD_CLOSE);
            jk_icon.setBackgroundResource(R.drawable.dd_close);
            dd_img.setBackgroundResource(R.drawable.off);
            dd_state = false;
        }
    }
}
